package com.yhyvr.console.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lz.kit.LogKit;
import com.lz.mybatis.jdbc.auto.dao.BoProxyPayLogMapper;
import com.lz.mybatis.jdbc.auto.model.BoProxyPayLog;
import com.lz.mybatis.jdbc.auto.model.BoProxyPayLogExample;
import com.lz.tool.LzStringUtils;
import com.yhyvr.console.annotation.RepeatSubmit;
import com.yhyvr.pojo.req.console.BootStrapGridReq;
import com.yhyvr.pojo.resp.CommonResp;
import com.yhyvr.pojo.resp.HttpResult;
import com.yhyvr.pojo.resp.console.BootStrapGridResp;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * title:
 * </p>
 * <p>
 * description:
 * </p>
 *
 * @create 张钦
 * @update
 * @version 1.0
 * @date
 */
@Controller
public class BoProxyPayLogController{
	@Resource
	private BoProxyPayLogMapper modelMapper;

	@RequestMapping("/console/bo_proxy_pay_log/add")
	@RepeatSubmit(isAdd = true)
	public String add(){
		return "console/boProxyPayLog/boProxyPayLog_form";
	}

	@RepeatSubmit(isAdd = true)
	@RequestMapping("/console/bo_proxy_pay_log/edit")
	public String edit(ModelMap modelMap,String id){
			modelMap.put("boProxyPayLog", modelMapper.selectByPrimaryKey(id));
		return "console/boProxyPayLog/boProxyPayLog_form";
	}

	@RequestMapping("/console/bo_proxy_pay_log/list")
	public String list(){
		return "console/boProxyPayLog/boProxyPayLog_table";
	}

	@RequestMapping("/console/bo_proxy_pay_log/json")
	public @ResponseBody
	BootStrapGridResp json(BootStrapGridReq bootGridReq){
		Page page = PageHelper.offsetPage(bootGridReq.getOffset(), bootGridReq.getLimit());
    	if(bootGridReq.getSort()!=null) {
    		page.setOrderBy(LzStringUtils.chageStringUpCaseAnd_(bootGridReq.getSort()) + " " + bootGridReq.getOrder());
    	}
		BoProxyPayLogExample boProxyPayLogExample = new BoProxyPayLogExample();
        ControllerQueryTool.setBoProxyPayLogCriteria(bootGridReq.getQuery(),boProxyPayLogExample.createCriteria());
		List<BoProxyPayLog> boProxyPayLogList = modelMapper.selectByExample(boProxyPayLogExample);
		return new BootStrapGridResp(page.getTotal(),boProxyPayLogList);
	}

	@RepeatSubmit(isAdd = false)
	@RequestMapping("/console/bo_proxy_pay_log/save")
	public @ResponseBody HttpResult save(String formObjectJson){
		try{
		BoProxyPayLog boProxyPayLog= JSON.parseObject(formObjectJson,BoProxyPayLog.class);
			String id=boProxyPayLog.getPayLogId();
		if (id!=null) {
			modelMapper.updateByPrimaryKeySelective(boProxyPayLog);
			return CommonResp.getSuccess();
		}else{
			modelMapper.insertSelective(boProxyPayLog);
			return CommonResp.getSuccess();
		}
		}catch(Exception e){
			LogKit.error(e.getMessage(),e);
			return CommonResp.getError();
		}

	}

	@RequestMapping("/console/bo_proxy_pay_log/delete")
	public @ResponseBody
	HttpResult delete(String ids){
		String[]idsa=ids.split(",");
		for (String id : idsa) {
		modelMapper.deleteByPrimaryKey(String.valueOf(id));
		}
		return CommonResp.getSuccess();
	}
}
